<?php
/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */

/**
 *  View User Databases
 */
?>
<div id="DBPage">
    <h3>Gérer mes bases de données</h3>

    <form action="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/ddatabase" method="post">
        <!-- Utilisateurs stockés en base de données -->
        <table class="tableContent">
            <tr>
                <th>
                    &nbsp;
                </th>
                <th>
                    Base de données
                </th>
                <th>
                    Hôte
                </th>
                <th>
                    Type
                </th>
                <th>
                    Profil
                </th>
            </tr>

            <?php
            require_once 'Library/Database.php';
            require_once 'Library/DB.php';
            $req = new Database_Model();
            $listDB = $req->GetDBByUser(Session::Get(Constants::$SESSION_cuser));
            $i = 0;
            foreach ($listDB as $oDB) {
                if ($i % 2)
                    echo '<tr class="style">';
                else
                    echo '<tr>';
                echo '<td>';
                echo '<input type="checkbox" name="chk-' . $oDB->GetID() . '" />';
                echo '</td>';
                echo '<td>';
                echo $oDB->GetNickname();
                echo '</td>';
                echo '<td>';
                echo $oDB->GetHost();
                echo '</td>';
                echo '<td>';
                echo $oDB->GetType()->GetName();
                echo '</td>';
                echo '<td>';
                echo $oDB->GetRule()->GetName();
                echo '</td>';
                echo '</tr>';
                $i++;
            }
            ?>
        </table>
        <br />
        <fieldset>
            <div class="legend"><span class="dDB">&nbsp;</span>Effacer les bases de données sélectionnées</div>
            (Effacer les liens entre les bases de données et mon profil.)<br />
            <input type="hidden" name="current-tab" value="<?php echo $j; ?>" />
            <input type="submit" value="Executer" />
        </fieldset>
    </form>
    <br />


    <form action="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/ndatabase" method="post">
        <fieldset>
            <div class="legend"><span class="aDB">&nbsp;</span>Ajouter une base de données</div>
            <table>
                <tr>
                    <td>
                        <label for="ipt-dbnname">Nom</label>
                    </td>
                    <td>
                        <input type="text" id="ipt-dbnname" name="nickname" /> <span class="description">( Nom du menu gauche )</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="ipt-dbhost">Hôte</label>
                    </td>
                    <td>
                        <input type="text" id="ipt-dbhost" name="host" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="ipt-dbport">Port</label>
                    </td>
                    <td>
                        <input type="number" pattern="[0-9]{4}" id="ipt-dbport" name="port" /> <span class="description">(Défaut : MySQL = 3306, Oracle = 1521)</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="ipt-dbname">Nom de la base</label>
                    </td>
                    <td>
                        <input type="text" id="ipt-dbname" name="dbname" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="sel-dbtype">Type de base</label>
                    </td>
                    <td>
                        <select name="dbtype" id="sel-dbtype">
                            <?php
                            $types = $req->GetAllType();
                            foreach ($types as $oType) {
                                echo '<option value="' . $oType->GetID() . '">' . $oType->GetName() . '</option>';
                            }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="sel-dbrule">Rôle</label>
                    </td>
                    <td>
                        <select name="dbrule" id="sel-dbrule">
                            <?php
                            $rules = $req->GetAllRule();
                            foreach ($rules as $oRule) {
                                echo '<option value="' . $oRule->GetID() . '">' . $oRule->GetName() . '</option>';
                            }
                            ?>
                        </select>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="current-tab" value="<?php echo $j; ?>" />
            <input type="submit" value="Executer" />
        </fieldset>   
    </form>

    <div class="ui-widget">
        <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                Liste les bases de données de l'utilisateur courant enregistrées dans la base de référence.</p>
        </div>
    </div>
</div>